import java.util.Scanner;

public class Test10 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        long[]array = new long[t];
        for (int i = 0; i < t; i++) {
            array[i] = scanner.nextLong();
        }
        //记录每次相加的值
        long count = array[0];
        //记录子数组的最大值
        long max = array[0];
        for (int i = 1; i < t; i++) {
            if(count < 0){
                //如果小于0就将count置为0,从新0开始加
                count = 0;
            }
           count = count+array[i];
           if(count > max){
               //如果大于最大值就更新max
               max = count;
           }

        }
        System.out.println(max);
    }
}
